/*
 *  util.h
 *  jscsh
 *
 *  Created by Jonathan Hohle on 1/8/08.
 *  Copyright 2008 hohle.net. All rights reserved.
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/kernel_types.h>
#include <time.h>
#include <JavaScriptCore/JavaScriptCore.h>

typedef struct _JSEHashEntry {
    char* property;
    JSValueRef value;
} JSEHashEntry;

char* createStringWithContentsOfFilePointer(FILE* f);
char* createStringWithContentsOfFile(const char* fileName);
char* UTF8CStringFromJSValueRef(JSContextRef context, JSValueRef stringRef);
JSValueRef JSValueRefFromUTF8CString(JSContextRef context, char* string);
JSValueRef JSValueRefMakeNewHash(JSContextRef context, size_t fieldCount, JSEHashEntry fields[]);
JSValueRef JSValueMakeErrnoError(JSContextRef context, errno_t errorNumber);
JSValueRef JSValueMakeDate(JSContextRef context, struct timespec time);
JSValueRef JSValueMakeArray(JSContextRef context);
struct timeval JSValueToTimeval(JSContextRef context, JSValueRef date, JSValueRef* exception);
void JSObjectAddClassMethod(JSContextRef context, JSObjectRef object, const char* methodName, JSObjectCallAsFunctionCallback method, JSPropertyAttributes attributes);